package cn.ajb.filemanager.util.md5;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.codec.binary.Hex;

/**
 * Md5加密
 * @author lx
 *
 */
public class Md5PwdImpl implements Md5Pwd{

	//加密
	public String  encode(String password){
		try {
			String algorithm = "MD5";
			//加盐  fghjkgddfgh
			//password = "erqwefghjkgddfghyuiwww";
			MessageDigest instance = null;
			try {
				instance = MessageDigest.getInstance(algorithm);
				
			} catch (NoSuchAlgorithmException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			//加密
			byte[] digest = instance.digest(password.getBytes("utf-8"));
			//十六进制加密
			char[] encodeHex = Hex.encodeHex(digest);
			
			return new String(encodeHex);
		} catch (UnsupportedEncodingException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		return password;
		
	}
	
}
